package com.sts.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.sts.bean.Base_eq;
import com.sts.bean.Eq_run;
import com.sts.dao.IBase_eqDao;


@Service
public class Base_eqService implements IBase_eqService{
	
	
	
	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource
	private IBase_eqDao baseDao ;

	@Override
	public boolean addBase_eq(Base_eq bs) {
		log.debug("addBase_eq service ---------");
		
		boolean result = false ;
		
		
		result = baseDao.insertBase_eq(bs) == 1 ;
		
		log.debug("addBase_eq service +++++++++");
		return result;
	}

	
	/**
	 * 查询所有设备
	 */
	@Override
	public List<Base_eq> selectBase() {
		
		log.debug("selectBase service ---------");

		List<Base_eq> list = new  ArrayList<Base_eq>() ;
		list = baseDao.selectBase_eq() ;
		
		log.debug("selectBase service +++++++++");
		return list;
	}


	@Override
	public boolean deleteById_S() {
		log.debug("selectById_S service ---------");
		
		boolean result = false ;
		
		
		result = baseDao.deleteById() == 1 ;
		
		log.debug("selectById_S service +++++++++");
		return result;
	}


	@Override
	public boolean deleteAll_S() {
		log.debug("selectAll_S service ---------");
		
		boolean result = false ;
		
		
		result = baseDao.deleteAll() == 1 ;
		
		log.debug("selectAll_S service +++++++++");
		return result;
	}


	@Override
	public List<Base_eq> selectEqMsg(String eq_id, String eq_name, String page1, String limit1) {
		
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		if(eq_id == null){
			eq_id = "";
		}
		if(eq_name == null){
			eq_name = "";
		}
		
		log.debug("service eq_id"+eq_id);
		log.debug("service car_id"+eq_name);
		
		if(page1 == null){
			page1 = "1" ;
		}
		if(limit1 == null){
			limit1 = "10";
		}
		int page = Integer.parseInt(page1) -1;
		int limit = Integer.parseInt(limit1) ;
		page = page * limit ;			//分页的起始位置
		map.put("eq_id", eq_id);
		map.put("eq_name", "%"+eq_name+"%");
		
		map.put("page", page);
		map.put("limit", limit);
		log.debug("map"+map);
		List<Base_eq> list = new ArrayList<Base_eq>() ;
		list = baseDao.selectEqMsg(map);
		
		return list;
	}


	@Override
	public int selectEqNum(String eq_id,String eq_name) {
		
		Map<String,Object> map = new HashMap<String,Object>();
		if(eq_id == null){
			eq_id = "";
		}
		if(eq_name == null){
			eq_name = "";
		}
		log.debug("service eq_id"+eq_id);
		log.debug("service car_id"+eq_name);
		map.put("eq_id", eq_id);
		map.put("eq_name", "%"+eq_name+"%");
		int num = baseDao.selectEqNum(map);
		return num;
	}


	@Override
	public List<Integer> selectEqID() {
		List<Integer> list = new ArrayList<Integer>() ;
		list = baseDao.selectEqID() ;
		return list;
	}
	
	

}
